package com.chinaisafe.user.vo.response;

import com.chinaisafe.gateway.sdk.enums.ClientTypeEnum;
import com.chinaisafe.user.entity.SysApp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;

/**
 * SysAppRespVO
 * Description：应用响应值对象
 *
 * @author tby
 * @date  2024-07-11 17:32:41
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@Schema(name = "SysAppRespVO", description = "应用响应值对象")
public class SysAppRespVO implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "主键id")
    private Long id;

    @Schema(description = "乐观锁版本")
    private Integer version;

    @Schema(description = "名称")
    private String name;

    @Schema(description = "应用端")
    private String clientType;

    @Schema(description = "应用分类")
    private String type;

    @Schema(description = "应用版本")
    private String appVersion;

    @Schema(description = "应用logo")
    private String logo;

    @Schema(description = "应用简介")
    private String summary;

    @Schema(description = "排序")
    private Integer seq;

    @Schema(description = "是否启用")
    private Boolean enable;


    /**
     * 将实体类转换为响应值对象
     * @param entity 实体对象
     * @return SysAppRespVO 响应值对象
     * @author tby
     * @date 2024-07-11 17:32:41
     */
    public static SysAppRespVO convertFromEntity(SysApp entity) {
        SysAppRespVO respVO = new SysAppRespVO();
        respVO.id = entity.getId();
        respVO.version = entity.getVersion();
        // 给对应的字段赋值 可根据实际业务删减
        respVO.name = entity.getName();
        respVO.clientType = entity.getClientType();
        respVO.type = entity.getType();
        respVO.appVersion = entity.getAppVersion();
        respVO.logo = entity.getLogo();
        respVO.summary = entity.getSummary();
        respVO.seq = entity.getSeq();
        respVO.enable = entity.getEnable();
        return respVO;
    }

    public String getClientTypeDesc() {
        ClientTypeEnum clientTypeEnum = ClientTypeEnum.getByCode(this.clientType);
        if (clientTypeEnum == null) {
            return "";
        }else {
            return clientTypeEnum.getDesc();
        }
    }
}
